
/**
 * COOKIE存储
 * @param {string} key 键
 * @param {string} val 数据
 * @param {number} s   时间/s
 */
function setcookie(key, val, s)
{
    if (typeof val == 'object') val = JSON.stringify(val)

    const d = new Date 
    d.setTime(  d.getTime() - 1000*60*60*8 + 1000*s )
    document.cookie = `${key}=${val}; expires=${d}`
}

/**
 * COOKIE获取
 * @param {string} key 键
 * @returns 
 */
function getcookie(key)
{
    let arr = document.cookie.split('; ')
    for (let i=0; i<arr.length; i++)
    {
        let item = arr[i]
        let temp = item.split('=')

        if (temp[0] == key){
            return temp[1]
        }
    } 
}

/**
 * COOKIE删除
 * @param {string} key 键
 */
function removecookie(key)
{
    setcookie(key, null, -1)
}